<template>
	<div style="width: 100%;overflow-y:auto;-webkit-overflow-scrolling: touch;">
        <div>
            <server-methods></server-methods>
        </div>
        <div>
            <server-question></server-question>
        </div>
		<!--<div class="content">
			<div>
                 <server-methods></server-methods>
                <div style="width:100%;height:3rem;margin-top:1rem;background:yellow;">

                </div>
            </div>
            <div>
			    <server-question></server-question>
                <div style="width:100%;height:50rem;background:pink;">

                </div>
            </div> 
		</div>-->
	</div>
</template>

<script>
import ServerMethods from "./serverMethods";
import ServerQuestion from "./serverQuestion";
import {mapGetters} from "vuex";
import axios from "axios";
import { CHANGE_NAVIGATION,NAVIGATE } from '../../config/postMessage-types';
	export default {
	  	name: 'hello',
	  	data () {
	    	return {
				
			}
		},
		computed: {
			...mapGetters('wxh', [
                'userInfo'
            ]),
            hasUserInfo() {
                return Object.keys(this.userInfo).length;
            },
		},
		components: {
			// "server-header": ServerHeader,
	        "server-methods": ServerMethods,
	        "server-question": ServerQuestion,
	    },
	    methods: {
	        getData() {
				// console.log(123456,'qwwwww');
            },
            //判断登录回传Rn
            isLogin(){
                    let userInfo = this.hasUserInfo;
                    let flag = true;
                    console.log(window.api.sessionId,'window.api.sessionId')
                    if(!userInfo){
                        let goBackIns = {
                            type: NAVIGATE,
                            params: {
                                screen: 'Login',
                                params:{
                                    FromWeb: true
                                }
                            }
                        }
                        window.postMessage(JSON.stringify(goBackIns));
                        flag = false;
                    }
                    console.log('判断登录')
                    return flag;
            },   
            //获取href的sessionId方法 返回对象
            getHrefSessionId(){
                let arr = window.location.href.split('?');
                let equeryArr = [];
                let toObj = [];
                let obj = {};
                if(arr.length == 2){
                    equeryArr = arr[1].split("&");
                    for(let i = 0; i < equeryArr.length; i++){
                        toObj.push(equeryArr[i].split('=')[0]);
                        toObj.push(equeryArr[i].split('=')[1]);
                    }
                    for(let j = 0; j < toObj.length; j++){
                        if(j % 2 === 0){
                            let str = toObj[j];
                            obj[str] = toObj[j+1];
                        }
                    }
                }
                return obj;
            }
	    },
		created () {
            let titleConfig = JSON.stringify({
                type: CHANGE_NAVIGATION,
                params: {
                    title: "服务中心"
                }
            })
            setTimeout(() => {
                window.postMessage(titleConfig)
            },300)
		},
		mounted () {
            let obj = this.getHrefSessionId();
            let flag = this.isLogin();
            if(!flag) return;
		},
		updated() {
			//页面更新完毕
		}
	}
</script>

<style scoped="scoped">
	.box{
		width: 100%;
	    height: 100%;
	    display: flex;
	    flex-direction: column;
	    justify-content: space-between;
	}
	.content{
        width: 100%;
		flex:1;
		overflow-y:auto;
        background:#efeff4;
	}
</style>